<?php
function nv_submenu ( $array_cat, $group_id = 0)
{
		global $global_config;		
		$html = NULL;
        $array_item = array();
        foreach ( $array_cat as $cat )
        {
            if ( $cat['group'] == $group_id )
            {
                $array_item[] = array( 
                    'id' => $cat['id'], 
					'title' => $cat['title'], 
					'alias' => $cat['alias'],
					'link' => $global_config['my_domain']."/".$cat['alias']								
                );	
            }
        }
        
        if ( ! empty( $array_item ) )
        { 		
            foreach ( $array_item as $cat )
            {
                $html.= '<li id="_mainMenuVideo">';
                $html.= '<a name="_mainMenu" id="_mainMenuVideoLink" class="w2 line" href="' .$cat['link']. '">' .$cat['title']. '</a>';
				$html.=  nv_submenu2 ( $array_cat, $cat['id'], $cat['link']);				
				$html.= '</li>';
            }            
            return $html;
        }        
}
function nv_submenu2 ( $array_cat, $group_id = 0, $linkroot)
{	
		global $global_config;
		$html = NULL;
		$array_item = array();
        foreach ( $array_cat as $cat )
        {			
            if ( $cat['group'] == $group_id )
            {				
                $array_item[] = array( 
                    'id' => $cat['id'], 
					'title' => $cat['title'], 
					'alias' => $cat['alias'],
					'link'	=> $linkroot ."/". $cat['alias']			
                );	
            }
        }
        
        if ( ! empty( $array_item ) )
        { 	
			$html.= '<div style="left: -5px;" id="_mainMenuVideoItems" class="abs smenu ws2 none">
                                        <div class="hsmenu">  
                                        	<div class="colsub1 wsub3 fleft">';	
            foreach ( $array_item as $cat )
            {                
                $html.= '<a href="' .$cat['link']. '" title="' .$cat['title']. '">' .$cat['title']. '</a>';
            }
			$html.= '</div>                                            
                           </div>
                              </div>';            
            return $html;
        }      
}
// nếu có sửa đổi thì xóa file cache/menu.php đi để nó cập nhật lại
if(!$cache->cacheFile('menu.php')){//kiểm tra xem cache có tồn tại ko	
	$data = $db->fetch_array("SELECT `id`,`title`,`alias`,`group`,`status`,`func` FROM tb_menu WHERE status = 1 ");
	
	$xtpl = new XTemplate( "themes/".$global_config['themes']."/modules/main/menu.tpl");
	$xtpl->assign( "ROOT_WEB",$global_config['my_domain'] );
	$xtpl->assign( "THEMES","themes/".$global_config['themes'] );		
	$xtpl->assign( "CONTENT", nv_submenu($data) );	
	$xtpl->parse( 'main' );
	$menu = $xtpl->text('main');
	$content.= $menu;
	$cache->closeFile($menu);// truyền dữ liệu cho cache	
}
else
	$content.=$cache->cacheFile('menu.php');// đọc file cache

?>

